package cash_access;

import java.io.Serializable;
import mware_lib.ObjectBroker;
import mware_lib.ObjectRef;

public class TransactionProxy extends TransactionImplBase {
  private ObjectRef object;

  public TransactionProxy(ObjectRef object) {
    this.object = object;
  }
  
  @Override
  public void deposit(String accountID, double amount) {
    Serializable result = ObjectBroker.instance().invokeRemoteMethod(object, "deposit", new Serializable[] {accountID, amount});
    if (result != null && result instanceof RuntimeException) 
      throw (RuntimeException)result;
  }

  @Override
  public void withdraw(String accountID, double amount) throws OverdraftException {
    Serializable result = ObjectBroker.instance().invokeRemoteMethod(object, "withdraw", new Serializable[] {accountID, amount});
    if (result != null && result instanceof OverdraftException)
      throw (OverdraftException)result;
    if (result != null && result instanceof RuntimeException)
      throw (RuntimeException)result;
  }

  @Override
  public double getBalance(String accountID) {
    Serializable result = ObjectBroker.instance().invokeRemoteMethod(object, "getBalance", new Serializable[] {accountID});
    if (result != null && result instanceof RuntimeException)
      throw (RuntimeException)result;
    return (double)result;
  }

}
